package org.zpengblog.cosdemo.domain;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 响应实体类.
* @author yuanxh
* @version 1.0.0
* CreateDate 2020年4月30日 下午5:39:17
* description 
*/
@Getter
@Setter
@ToString
public class Result {

  /**
   * 编码.
   */
  private int code;
  
  /**
   * 提示.
   */
  private String msg;
  /**
   * 数据.
   */
  private Object data;

  /**
   * 默认初始化.
   */
  public Result() {
    
  }
  
  /**
   * 带参初始化.
   * @param code
   * @param msg
   * @param data
   */
  public Result(int code, String msg, Object data) {
    this.code = code;
    this.msg = msg;
    this.data = data;
  }
  
  
  /**
   * 成功.
   * @return Result
   */
  public static Result success() {
    
     return new Result(0, "success", null);
  }

  /**
   *专门为从app来的数据设置的成功.
   * @return Result
   */
  public static Result success(Integer code) {
     return new Result(code, "success", null);
  }
  /**
   * 带data成功.
   * @param data data
   * @return Res
   */
  public static Result success(Object data) {
      return new Result(0, "success", data);
  }

  /**
   * 带msg和data成功.
   * @param data data
   * @param msg msg
   * @return Result
   */
  public static Result success(Object data, String msg) {
     
      return new Result(0,  msg, data);
  }  
  
  
  /**
   * 带msg失败.
   * @param msg
   * @return
   */
  public static Result failure(String msg) {
     
      return new Result(-1, msg, null);
  }

  /**
   * 带data失败.
   * @param msg
   * @return
   */
  public static Result failure(Object data) {
     
      return new Result(-1, "请求失败", data);
  }
  
  /**
   * 带code和msg失败.
   * @param code
   * @param msg
   * @return
   */
  public static Result failure(int code, String msg) {
      return  new Result(code, msg, null);
  }

  

 

}
